<!doctype html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>运维功能——定时清洗SQL页面查看</title>
    <script src="/webjars/miniui/boot.js" type="text/javascript"></script>
    <script src="/static/js/common/common.js" type="text/javascript"></script>
    <link href="/static/css/resource.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        body {
            margin:0;
            padding:0;
            border:0;
            width:100%;
            height:100%;
            overflow:hidden;
        }
    </style>
</head>
<body>
<div class="role-search">
    <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;">
        <table>
            <tr>
                <td style="width: 100%;">
                    <a class="mini-button" iconCls="fa fa-plus" onclick="addSql()" plain="true">新增</a>
                </td>
                <td class="discell" style="white-space: nowrap;text-align:right;">省份:</td>
                <td>
                    <input name="setProvince" id="setProvince" class="mini-combobox" style="width: 140px" showNullItem="true"
                           textField="codeName" valueField="codeId" emptyText="请选择..." />
                </td>
                <td style="white-space: nowrap;text-align:right;">
                    <input class="mini-textbox" id="remark" class="mini-textbox" emptyText="sql名称" onenter="onKeyEnter" />
                    <a class="mini-button" plain="true" iconCls="fa fa-search" plain="true" onclick="search()">查询</a>
                </td>
            </tr>
        </table>
    </div>
</div>

<!--撑满页面-->
<div class="mini-fit">
    <div id="datagrid1" class="mini-datagrid" style="width: 100%; height: 100%;" ajaxType="get" multiSelect="false"
         sizeList="[20,50,100]" pageSize="50" virtualScroll="false" showLoading="true"
         idField="id" url="/azbj/dsqx/selectAll">
        <input name="orgid" class="mini-hidden" style="width: 100%;" readonly />
        <div property="columns">
            <div type="indexcolumn" width="10" headerAlign="center">序号</div>
            <div name="remark" field="remark" align="center" width="20" headerAlign="center" allowSort="false">名称</div>
            <div name="content" field="content" align="center" headerAlign="center" allowSort="false">内容</div>
            <div name="type" field="type" align="center" width="15" renderer="executeState" headerAlign="center">是否执行</div>
            <div name="province" field="province" align="center" width="15" renderer="setProvinces" headerAlign="center">作用省份</div>
            <div name="action" headerAlign="center" align="center" width="35" renderer="onActionRenderer" cellStyle="padding:0;"
                 allowSort="false" multiSelect="false">操作
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    mini.parse();
    var provinceArr = ${provinceArr!};
    var provinceMapArr = [];
    var grid = mini.get("datagrid1");
    var flag = mini.get("flag");
    var province = mini.get("setProvince");
    grid.load();

    $(function (){
        //getProvince();
        var n = 0;
        provinceMapArr[n] = {codeId: '-1', codeName: '通用'};
        for(var item in provinceArr){
            provinceMapArr[++n] = {codeId: item.slice(0,2), codeName: provinceArr[item]};
        }
        province.setData(provinceMapArr);
        provinceArr[-10000]='通用';
    });

    //拿到省份
    function getProvince(){
        $.ajax({
            url: '/azbj/sjtjfx/xzzttj/getProvince',
            type: "GET",
            success: function (res) {
                res.unshift({codeId: '-1', codeName: '通用'});
                province.setData(res);
            }
        });
    }

    //渲染列中按钮
    function onActionRenderer(e) {
        var s = '';
        s += '&nbsp;<a class="mini-button mini-button-info"  onclick="checkorupdateposition(2)" >&nbsp;查看&nbsp;</a>&nbsp';
        if(e.row.type === '0' || e.row.type === '1'){
            s += '&nbsp;<a class="mini-button mini-button-primary"  onclick="checkorupdateposition(3)" >&nbsp;编辑&nbsp;</a>&nbsp';
        }
        //暂时去掉删除按钮
        //s += '&nbsp;<a class="mini-button mini-button-danger"   onclick="delposition();" >&nbsp;删除&nbsp;</a>&nbsp';
        return s;
    }

    //新增数据
    function addSql() {
        commonEdit("/azbj/dsrw/regularCleanSql/addOrSelect/view?flag=1", "新增", null, 600, 500, true, false, true, callback);
        function callback() {
            grid.reload();
        }
    }

    //查看数据
    function checkorupdateposition(type){
        var row = grid.getSelected();
        if (row) {
            commonEdit("/azbj/dsrw/regularCleanSql/addOrSelect/view?flag="+type, "查看", row, 600, 500, true, false, true, callback);
            function callback() {
                grid.reload();
            }
        } else {
            mini.alert("请至少选择一条数据！");
        }
    }

    //删除数据
    function delposition() {
        var row = grid.getSelected();
        if (row) {
            commonRemove("/azbj/dsqx/delSql/" + row.id, row, {_method: "delete"}, callback);
            function callback() {
                grid.reload();
            }
        } else {
            mini.alert("请至少选中一条记录");
        }
    }

    //查询
    function search() {
        var params = {
            province: province.getValue(),
            remark: mini.get("remark").getValue()
        }
        grid.load(params);
    }

    //渲染sql类别
    function sqlSort(e) {
        var Statedata = [{id: 1, text: '新增'}, {id: 2, text: '删除'}, {id: 3, text: '更新'}, {id: 4, text: '查询'}];
        for (var i = 0, l = Statedata.length; i < l; i++) {
            var g = Statedata[i];
            if (g.id == e.value) return g.text;
        }
    }

    //渲染执行类别
    function executeState(e) {
        var Statedata = [{id: 0, text: '未启用'}, {id: 1, text: '待执行'}, {id: 2, text: '已执行'}, {id: 3, text: '执行失败'}];
        for (var i = 0, l = Statedata.length; i < l; i++) {
            var g = Statedata[i];
            if (g.id == e.value) return g.text;
        }
    }

    //渲染省份
    function setProvinces(e){
        var returnProvince = '';
        var filtrationArr = e.value.split(',')
        for(var i=0;i<filtrationArr.length;i++){
            returnProvince += provinceArr[filtrationArr[i]+'0000']+','
        }
        return returnProvince.slice(0,returnProvince.length-1);
    }
</script>
</body>
</html>